damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README | LICENSE

[locale].tsx (2110B)


      1 import { GetStaticPaths, GetStaticProps } from 'next';
      2 import { useRouter } from 'next/router';
      3 import Image from 'next/image'
      4 import { Inter } from 'next/font/google'
      5 import { Hero } from '@/components/sections/Hero'
      6 import Head from "next/head";
      7 import { IntlProvider, useIntl } from 'react-intl'
      8 import { BannedInChina } from '@/components/sections/BannedInChina'
      9 import { DamusOnMedia } from '@/components/sections/DamusOnMedia';
     10 import { MeetTheTeam } from '@/components/sections/MeetTheTeam';
     11 import { DamusAroundTheWorld } from '@/components/sections/DamusAroundTheWorld';
     12 import { Footer } from '@/components/sections/Footer';
     13 import { DamusLiveEvents } from '@/components/sections/DamusLiveEvents';
     14 import { Contribute } from '@/components/sections/Contribute';
     15 import { FinalCTA } from '@/components/sections/FinalCTA';
     16 import { Benefits } from '@/components/sections/Benefits';
     17 import { Home } from '@/components/pages/home';
     18 import { useMemo } from 'react';
     19 import English from "../../content/compiled-locales/en.json";
     20 import Japanese from "../../content/compiled-locales/ja.json";
     21 
     22 
     23 export default function LocaleHome({ locale }: { locale: string }) {
     24     const [shortLocale] = locale ? locale.split("-") : ["en"];
     25 
     26     const messages = useMemo(() => {
     27       switch (shortLocale) {
     28           case "en":
     29               return English;
     30           case "ja":
     31             return Japanese;
     32           default:
     33               return English;
     34       }
     35     }, [shortLocale]);
     36 
     37     return (<>
     38       <IntlProvider
     39             locale={shortLocale}
     40             messages={messages}
     41             onError={() => null}>
     42             <Home/>
     43         </IntlProvider>
     44     </>)
     45 }
     46 
     47 export const getStaticPaths: GetStaticPaths = async () => {
     48   // Define your locales
     49   const locales = ['en-US', 'ja-JP'];
     50 
     51   // Generate paths
     52   const paths = locales.map((locale) => ({
     53     params: { locale },
     54   }));
     55 
     56   return { paths, fallback: false };
     57 };
     58 
     59 export const getStaticProps: GetStaticProps = async (context) => {
     60   const { params } = context;
     61   const locale = params?.locale;
     62 
     63   return {
     64     props: {
     65       locale,
     66     }
     67   };
     68 };